﻿using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using DXApplicationTangche.DTO;
using DXApplicationTangche.report;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.项目流程.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.项目流程
{
    public partial class Form成果物预览 : Form
    {
        private OrderTaskDTO orderTaskDTO;
        private string reportPath;
        private XtraReport项目成果物 report;
        public Form成果物预览(OrderTaskDTO orderTaskDTO)
        {
            InitializeComponent();
            this.orderTaskDTO = orderTaskDTO;
            //任务信息
            bindData();
            if ("SAMPLEPREPARATION_001".Equals(this.orderTaskDTO.code))
            {
                //成果物
                report = new XtraReport项目成果物(this.orderTaskDTO.orderId);
                ReportPrintTool tool = new ReportPrintTool(report);
                this.splitContainerControl1.Panel2.Controls.Clear();
                tool.PreviewForm.TopLevel = false;
                this.splitContainerControl1.Panel2.Controls.Add(tool.PreviewForm);
                tool.Report.ShowPreview();
            }
            else
            {
                this.splitContainerControl1.Panel2.Controls.Clear();
            }
        }
        /// <summary>
        /// 任务相关信息
        /// </summary>
        private void bindData()
        {
            this.textBox计划开始时间.Text = this.orderTaskDTO.startTimePlanned == DateTime.MinValue ? "" : this.orderTaskDTO.startTimePlanned.ToString();
            this.textBox实际完成时间.Text = this.orderTaskDTO.actualFinishDate == DateTime.MinValue ? "" : this.orderTaskDTO.actualFinishDate.ToString();
            this.textBox任务描述.Text = this.orderTaskDTO.activityDescription;
            this.textBox任务负责人.Text = this.orderTaskDTO.responsor;
            this.textBox执行人.Text = this.orderTaskDTO.assignee;
        }

        private void simpleButton任务完成_Click(object sender, EventArgs e)
        {
            if ("SAMPLEPREPARATION_001".Equals(this.orderTaskDTO.code))
            {
                //生成pdf文件到本地项目下指定文件
                reportPath = @"doc\" + this.orderTaskDTO.orderId + "-" + this.orderTaskDTO.activityDescription +  "项目成果物" + ".pdf";
                PdfExportOptions pdfOptions = report.ExportOptions.Pdf;
                report.ExportToPdf(reportPath);
                new Form任务完成扫员工(this.orderTaskDTO, reportPath).ShowDialog();
            }
            else
            {
                new Form任务完成扫员工(this.orderTaskDTO).ShowDialog();
            }
            this.Close();
        }
    }
}

